/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 02.01.2006
 *
 *************************************************/
package fightplan.persistence;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.List;

import javax.swing.JOptionPane;

import fightplan.business.Fighter;
import fightplan.business.Tournament;

public class OldImport {

	public static void imprt(Tournament tournament, File file) {
		try {
			FileInputStream fis = new FileInputStream(file);
			ObjectInputStream ios = new ObjectInputStream(fis);
			List<Fighter> fighters = FilePersistence.readFighters(ios, tournament);
			ios.close();
			fis.close();
			for (Fighter fighter : fighters) {
				boolean existing = false;
				for (Fighter exstingFighter : tournament.getFighters()) {
					if (exstingFighter.compareTo(fighter) == 0) {
						existing = true;
						break;
					}
				}
				if (!existing) {
					tournament.getFighters().add(fighter);
				}
			}
		} catch (Exception x) {
			x.printStackTrace();
			JOptionPane.showMessageDialog(null, "Import fehlgeschlagen: " + x.getMessage(), "Fehler",
					JOptionPane.ERROR_MESSAGE);
		}

	}

}
